Optical imaging sensors are widely employed in today's electronic devices from digital cameras to other portable devices. An optical image sensor includes an array of sensing pixels and supporting logic circuitry that converts optical images to digital data. Performance of the optical image sensor can be improved by improving light sensing of individual pixels, crosstalk between pixels, and/or algorithms used by the supporting logic circuitry. However, the optical image sensor cannot perform well if the image is out of focus. Therefore, phase detection pixels are incorporated in optical image sensors to automatically locate where a lens should focus, without blindly scanning the whole range to try to detect a correct position for the lens.